<template>
	<view class="order">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				订单详情
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop clearfix" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="left fl">
				{{info.statustitle}}
			</view>
			<view class="right fr" v-if="role_id != 12">
				<view class="name" v-if="info.money != null && info.money !== ''">支付：{{info.money}}元</view>
			</view>
		</view>
		<view class="nr">
			<view class="list">
				<view class="liebiao clearfix">
					<view class="left fl">订单编号：</view>
					<view class="right fl">
						<view class="title">{{info.out_order_no}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">订单类型：</view>
					<view class="right fl">
						<view class="title" v-if="info.member_id">会员订单</view>
						<view class="title" v-else>普通订单</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 2">
					<view class="left fl">商品名称：</view>
					<view class="right fl">
						<view class="title">{{info.goodscharger_name!=null?info.goodscharger_name:''}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.member_id != 0">
					<view class="left fl">会员：</view>
					<view class="right fl">
						<view class="title" v-if="info.huiyuan_jmleixing == 1">减免{{info.huiyuan_jmshichang}}小时</view>
						<view class="title" v-if="info.huiyuan_jmleixing == 2">减免{{info.huiyuan_jmjie}}元</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.coupons_id">
					<view class="left fl">优惠券：</view>
					<view class="right fl">
						<view class="title" v-if="info.youhui_jmleixing == 2">减免{{info.youhui_minus}}小时</view>
						<view class="title" v-if="info.youhui_jmleixing == 1">减免{{info.youhui_minus}}元</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">借用地点：</view>
					<view class="right fl">
						<view class="title">{{info.dizhi}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">归还地点：</view>
					<view class="right fl">
						<view class="title">{{info.ghdizhi}}</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">设备编码：</view>
					<view class="right fl">
						<view class="title">{{info.charge_number}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">借用卡口：</view>
					<view class="right fl">
						<view class="title">{{info.duankou}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">宝编码：</view>
					<view class="right fl">
						<view class="title">{{info.charge_bao_sn}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">宝类型：</view>
					<view class="right fl">
						<view class="title" v-if="info.bao_leixing == 1">普通宝</view>
						<view class="title" v-else>快充宝</view>
					</view>
				</view>
				<view class="liebiao clearfix">
					<view class="left fl">支付方式：</view>
					<view class="right fl">
						<view class="title">{{info.pay_type}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="role_id != 12">
					<view class="left fl">下单时间：</view>
					<view class="right fl">
						<view class="title">{{info.sdate}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="info.attr == 1">
					<view class="left fl">使用时长：</view>
					<view class="right fl">
						<view class="title">{{info.sjshichang}}</view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="role_id != 12">
					<view class="left fl">结束时间：</view>
					<view class="right fl">
						<view class="title" v-if="info.edate != null">{{info.edate}}</view>
						<view class="title" v-else></view>
					</view>
				</view>
				<view class="liebiao clearfix" v-if="role_id != 12">
					<view class="left fl">结算方式：</view>
					<view class="right fl">
						<view class="title" v-if="info.fcfangshi != null">{{info.fcfangshi}}</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="info.attr == 1">
			<!-- 管理员 -->
			<view class="footer clearfix" v-if="role_id == 1">
				<view class="submit" @click="quxiao" v-if="info.status == 1">取消</view>
				<view class="submit" @click="tuikuan" v-if="info.status != 8">退款</view>
				<view class="submit" @click="huifu" v-if="info.status == 5 && info.fcfangshi == 3">恢复</view>
			</view>
			<!-- 代理商或者员工 -->
			<view class="footer clearfix" v-if="(role_id == 11 || role_id == 13) && order_status == 1">
				<view class="submit" @click="quxiao" v-if="info.status == 1">取消</view>
				<view class="submit" @click="huifu" v-if="info.status == 5 && info.fcfangshi == 3">恢复</view>
			</view>
		</view>
		<view class="beijing" v-if="hidden" @click="hidden = false"></view>
		<view class="tankuang" v-if="hidden">
			<view class="content">
				<view class="title">退款金额</view>
				<view class="form">
					<view class="liebiao clearfix">
						<view class="left fl">退款金额：</view>
						<view class="right fl">
							<input placeholder="请输入退款金额" v-model="money"></input>
						</view>
					</view>
					<view class="liebiao clearfix">
						<view class="left fl">退回方式：</view>
						<view class="right fl">
							<radio-group name="type" @change="typeChange">
								<label>
									<radio :value="1" checked="checked" /><text>原路返回</text>
								</label>
								<label style="margin-left: 10rpx;">
									<radio :value="2" /><text>退回余额</text>
								</label>
							</radio-group>
						</view>
					</view>
					<view class="submit" @click="submit11">退款</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				agent_id: '',
				role_id: '',
				id: '',
				hidden: false,
				money: '',
				type: 1,
				info: {
					status: '',
					statustitle: '',
					money: '',
					danhao: '',
					sdate: '',
					ghdizhi: '',
					dizhi: '',
					charge_number: '',
					duankou: '',
					charge_bao_sn: '',
					bao_leixing: '',
					sjshichang: '',
					pay_type: '',
					edate: '',
					attr: '',
					huiyuan_jmleixing: '',
					huiyuan_jmshichang: '',
					huiyuan_jmjie: '',
					coupons_id: '',
					youhui_jmleixing: '',
					youhui_minus: '',
					fcfangshi: '',
					goodscharger_name: '',
					pingtai: '',
				},
				order_status: 2, //代理商、员工 订单管理状态 1：可以管理 2：不可以管理
			}
		},
		onLoad(options) {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}

			this.agent_id = uni.getStorageSync('agent_id');
			this.role_id = uni.getStorageSync('role_id');

			this.id = options.id;

			this.request({
				url: '/xcx/orderDetail',
				data: {
					id: this.id,
					agent_id: this.agent_id,
					role_id: this.role_id,
				},
				method: "POST"
			}).then(res => {
				if (res.data.code == 200) {
					this.info = res.data.data;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})

			//获取基本配置信息
			this.request({
				url: '/xcx/webconfig',
				data: {}
			}).then(res => {
				if (res.data.code == 200) {
					this.order_status = res.data.data.order_status;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
		},
		methods: {
			typeChange(item) {
				this.type = item.detail.value;
			},
			//退款接口
			tuikuan() {
				this.hidden = !this.hidden;
			},
			submit11() {
				if (this.money == '') {
					uni.showToast({
						title: '请输入退款金额！',
						icon: 'none'
					})
				}
				
				if(this.info.pingtai == 0){
					this.request({
						url: '/orderx/refunds',
						data: {
							id: this.id,
							money: this.money,
							type: this.type
						},
						method: "POST"
					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.code == undefined) {
								this.hidden = false;
								uni.showToast({
									title: '退款成功',
									icon: 'none'
								})
								setTimeout(function() {
									uni.navigateBack()
								}, 1000)
					
							} else {
								uni.showToast({
									title: res.data.data.message,
									icon: 'none'
								})
							}
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							})
						}
					})
				}else if(this.info.pingtai == 1){
					this.request({
						url: '/alipay/refund',
						data: {
							id: this.id,
							money: this.money,
							type: this.type
						},
						method: "POST"
					}).then(res => {
						if (res.data.code == 200) {
							if (res.data.data.code == undefined) {
								this.hidden = false;
								uni.showToast({
									title: '退款成功',
									icon: 'none'
								})
								setTimeout(function() {
									uni.navigateBack()
								}, 1000)
					
							} else {
								uni.showToast({
									title: res.data.data.message,
									icon: 'none'
								})
							}
						} else {
							uni.showToast({
								title: res.data.message,
								icon: 'none'
							})
						}
					})
				}
			},
			//取消订单
			quxiao() {
				this.request({
					url: '/xcx/ordercancel',
					data: {
						id: this.id,
						agent_id: this.agent_id,
						role_id: this.role_id,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})

						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
				})
			},
			//恢复订单
			huifu() {
				this.request({
					url: '/xcx/orderresume',
					data: {
						id: this.id,
						agent_id: this.agent_id,
						role_id: this.role_id,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '操作成功',
							icon: 'none'
						})

						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					}
				})
			},
			fanhui() {
				uni.navigateBack();
			},
		}
	}
</script>

<style lang="scss" scoped>
	.order {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;

			.left {
				font-size: 32rpx;
				color: #333333;
				font-weight: 700;
			}

			.right {
				height: 36rpx;
				line-height: 36rpx;
				text-align: center;
				margin-top: 6rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-left: 10rpx;
					margin-right: 6rpx;
				}

				.name {
					font-size: 24rpx;
					color: #333333;
				}
			}
		}

		.nr {
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -200rpx;
			box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;

			.list {
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 40rpx 40rpx 10rpx;
				position: relative;

				.liebiao {
					margin-bottom: 30rpx;

					.left {
						font-size: 24rpx;
						color: #333333;
						width: 40%;
					}

					.right {
						width: 58%;

						.title {
							font-size: 24rpx;
							color: #333333;
							width: 100%;
							word-break: break-all;
						}

						.name {
							font-size: 24rpx;
							color: #5C88FA;
						}
					}
				}
			}
		}

		.footer {
			width: 90%;
			margin: 100rpx auto 0;

			.submit {
				float: left;
				width: 28%;
				text-align: center;
				margin-right: 8%;
				height: 72rpx;
				line-height: 72rpx;
				background: linear-gradient(90deg, #65bdfc, #398ef8);
				border-radius: 36rpx;
				color: #FFFFFF;
				font-size: 30rpx;
			}

			.submit:last-child {
				margin-right: 0;
			}
		}
		
		.beijing {
			position: fixed;
			width: 100%;
			height: 100%;
			top: 0;
			left: 0;
			background: #000000;
			opacity: 0.5;
			z-index: 120;
		}
		
		.tankuang {
			position: fixed;
			width: 80%;
			top: 36%;
			left: 10%;
			z-index: 130;
		
			.content {
				width: 100%;
				background: #ffffff;
				padding-bottom: 30rpx;
				border-radius: 20rpx;
		
				.title {
					width: 100%;
					padding-top: 30rpx;
					text-align: center;
					font-size: 36rpx;
					color: #000000;
					font-weight: 600;
				}
		
				.form {
					width: 86%;
					margin: 0 auto;
					margin-top: 50rpx;
					
					.liebiao {
						height: 80rpx;
						line-height: 80rpx;
						margin-bottom: 20rpx;
						
						.right{
							width: 70%;
						}
						
						input {
							height: 80rpx;
							line-height: 80rpx;
							width: 100%;
							color: #838383;
							border: 1rpx solid #f9f9f9;
							font-size: 28rpx;
							padding: 0 3%;
							box-sizing: border-box;
						}
					}
		
					.submit {
						width: 100%;
						background: linear-gradient(90deg, #65bdfc, #398ef8);
						border-radius: 45rpx;
						border-top-left-radius: 0;
						border-bottom-left-radius: 50rpx;
						color: #ffffff;
						font-size: 30rpx;
						height: 90rpx;
						line-height: 90rpx;
						text-align: center;
						margin-top: 60rpx;
					}
				}
			}
		}
	}
</style>